package org.apache.ibatis.demo.handler;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * UserTypeHandler
 *
 * @author zhaohui
 */
public class MyAmountHandler implements TypeHandler<MyAmount> {


    @Override
    public void setParameter(PreparedStatement ps, int i, MyAmount parameter, JdbcType jdbcType) throws SQLException {
        ps.setBigDecimal(i, parameter.bigDecimalValue());
    }

    @Override
    public MyAmount getResult(ResultSet rs, String columnName) throws SQLException {
        return new MyAmount(rs.getBigDecimal(columnName));
    }

    @Override
    public MyAmount getResult(ResultSet rs, int columnIndex) throws SQLException {
        return new MyAmount(rs.getBigDecimal(columnIndex));
    }

    @Override
    public MyAmount getResult(CallableStatement cs, int columnIndex) throws SQLException {
        return new MyAmount(cs.getBigDecimal(columnIndex));
    }
}
